﻿
namespace Patterns4Net.Tests.ArchitectureExplorer.Diagram.Services
{
    using System.IO;
    using System.Linq;
    using NUnit.Framework;
    using Patterns4Net.ArchitectureExplorer.Diagram.Services;
    using Attributes.Relations;

    [TestFixture]
    public class MergeRelationsTest
    {
        [Test]
        public void Merges_Two_Compositions()
        {
            var builder = new DiagramBuilder();
            builder.AddLayer("test-layer")
                .AddPackage("test-pkg")
                .Add("A")
                .Add("B");
            var diagram = builder.Build();
            diagram.AddComposition("A", "B");
            diagram.AddComposition("B", "A", Cardinality.Multiple);

            var service = new MergeRelations();
            service.UpdateDiagram(diagram, new StreamWriter(new MemoryStream()));

            Assert.AreEqual(1, diagram.Relations.Count());
            var relation = diagram.Relations.First();
            Assert.AreEqual("A", relation.Source.Name);
            Assert.AreEqual("B", relation.Target.Name);
            Assert.AreEqual(Cardinality.One, relation.TargetCardinality);
            Assert.AreEqual(Cardinality.Multiple, relation.SourceCardinality);
        }

        [Test]
        public void Does_Not_Merge_Two_Inheritances()
        {
            var builder = new DiagramBuilder();
            builder.AddLayer("test-layer")
                .AddPackage("test-pkg")
                .Add("A")
                .Add("B");
            var diagram = builder.Build();
            diagram.AddInheritance("A", "B");
            diagram.AddInheritance("B", "A");

            var service = new MergeRelations();
            service.UpdateDiagram(diagram, new StreamWriter(new MemoryStream()));

            Assert.AreEqual(2, diagram.Relations.Count());
        }
    }
}
